package com.kcwl.carrier.infrastructure.repository.persostence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.kcwl.carrier.domain.repository.IVehicleFastBindingInfoRepository;
import com.kcwl.carrier.infrastructure.repository.mapper.VehicleFastBindingInfoMapper;
import com.kcwl.carrier.infrastructure.repository.po.VehicleFastBindingInfoPO;
import com.kcwl.ddd.application.constants.YesNoEnum;
import com.kcwl.ddd.domain.repository.BaseRepositoryImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wulihai
 * @date 2019-04-10
 */
@Slf4j
@Service
public class VehicleFastBindingInfoImpl extends BaseRepositoryImpl<VehicleFastBindingInfoMapper, VehicleFastBindingInfoPO> implements IVehicleFastBindingInfoRepository {
    @Resource
    private VehicleFastBindingInfoMapper fastBindingInfoMapper;

    @Override
    public List<Long> selectFastBindingVehicleIdByIds(List<Long> vehicleIdList) {
        QueryWrapper<VehicleFastBindingInfoPO> wrapper = new QueryWrapper<>();
        wrapper.in("vehicle_id", vehicleIdList);
        wrapper.eq("related_poof_modify_flag", YesNoEnum.YEA.getValue());
        List<VehicleFastBindingInfoPO> pos = fastBindingInfoMapper.selectList(wrapper);
        return pos.stream().map(VehicleFastBindingInfoPO::getVehicleId).collect(Collectors.toList());
    }

    @Override
    public void cancelHilight(Long vehicleId) {
        UpdateWrapper<VehicleFastBindingInfoPO> wrapper = new UpdateWrapper<>();
        wrapper.set("related_poof_modify_flag", YesNoEnum.NAY.getValue());
        wrapper.eq("vehicle_id", vehicleId);
        VehicleFastBindingInfoPO po = new VehicleFastBindingInfoPO();
        po.setRelatedPoofModifyFlag(YesNoEnum.NAY.getValue());
        fastBindingInfoMapper.update(po, wrapper);
    }
}
